# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=gzip
pkgver=1.13
pkgrel=0
pkgdesc="Popular data compression program"
subpackages="$pkgname-doc"
url="https://www.gnu.org/software/gzip/"
arch="all"
license="GPL-3.0-or-later"
depends="less"
checkdepends="diffutils grep perl"
source="https://ftp.gnu.org/gnu/gzip/gzip-$pkgver.tar.xz"

# secfixes:
#   1.12-r0:
#     - CVE-2022-1271

build() {
	# avoid text relocation
	export DEFS="NO_ASM"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info
	make
}

check() {
	make check
}

package() {
	make DESTDIR=$pkgdir install

	rm -rf "$pkgdir"/usr/lib/charset.alias
	rmdir -p "$pkgdir"/usr/lib 2>/dev/null || true

	mkdir -p "$pkgdir"/bin
	mv "$pkgdir"/usr/bin/gzip "$pkgdir"/usr/bin/gunzip "$pkgdir"/bin/
	ln -s /bin/gzip "$pkgdir"/usr/bin/gzip
	ln -s /bin/gunzip "$pkgdir"/usr/bin/gunzip

	# http://bugs.alpinelinux.org/issues/4011
	ln -sf /bin/gunzip "$pkgdir"/usr/bin/uncompress
}

sha512sums="
e3d4d4aa4b2e53fdad980620307257c91dfbbc40bcec9baa8d4e85e8327f55e2ece552c9baf209df7b66a07103ab92d4954ac53c86c57fbde5e1dd461143f94c  gzip-1.13.tar.xz
"
